package cn.otrue.patienthealthmanager.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.utils.DensityUtil;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class MainInfoAdapter extends BaseAdapter {


	private TextView tv_main_info_name;
	private TextView tv_main_info_time;
	private TextView tv_main_info_other;


	public void ImageSet(String imgurl, ImageView img_headPhoto) {

		DisplayImageOptions options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.iv_user_photo)
				.showImageOnFail(R.drawable.iv_user_photo)
				.showImageForEmptyUri(R.drawable.iv_user_photo)
				.cacheInMemory(true)
				.cacheOnDisk(true)
				.bitmapConfig(Bitmap.Config.RGB_565)
				.displayer(
						new RoundedBitmapDisplayer(DensityUtil.dip2px(context,
								45))).build();
		ImageLoader.getInstance().displayImage(imgurl, img_headPhoto, options);
	}
	private List<Map<String, String>> butt;
	private LayoutInflater inflater;
	private Context context;

	public MainInfoAdapter(Context context, List<Map<String, String>> butt) {
		super();
		this.butt = butt;
		inflater = LayoutInflater.from(context);
		this.context = context;
	}

	@Override
	public int getCount() {

		return butt.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		View view = inflater.inflate(R.layout.item_main_info_lv, null);
		tv_main_info_other = (TextView) view
				.findViewById(R.id.tv_main_info_other);
		tv_main_info_name = (TextView) view
				.findViewById(R.id.tv_main_info_name);
		tv_main_info_time = (TextView) view
				.findViewById(R.id.tv_main_info_time);
		 ImageView 	iv_main_info_img = (ImageView) view
	.findViewById(R.id.iv_main_info_img);
		Map<String, String> map = butt.get(arg0);
		tv_main_info_name.setText("标题："+map.get("title"));
		tv_main_info_time.setText("时间："+map.get("businesstime"));
		tv_main_info_other.setText("类型："+map.get("typename"));
		
			try {
				String url= map.get("headimg");
						
				ImageSet(url,iv_main_info_img);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		
		
		
		return view;
	}
}
